/*
 * an_leksykalny.cpp
 *
 *  Created on: Feb 26, 2009
 *      Author: karol
 */

#include <iostream>

#include "definicje.h"

int value;
int charCount = 0;

char getChar()
{
	charCount++;
    return std::cin.get();
}

int getLeksem() {
	char c, buf;
	bool ready = false;
	int multi = 1;

	while(std::cin.peek() == ' ' || std::cin.peek() == '\n' || std::cin.peek() == '\t') {
		getChar();
	}

	if (std::cin.peek() == EOF)
		return 0;

	switch (c = getChar()) {
		case '-':
			if (((buf = std::cin.peek()) < '0') || (buf > '9')) {
				return '-';
			} else {
				multi = -1;
			}
		case '1':
		case '2':
		case '3':
		case '4':
		case '5':
		case '6':
		case '7':
		case '8':
		case '9':
			if (c >= '1' && c <= '9') {
				value = c - '0';
			} else {
				value = 0;
			}
			while (((c = std::cin.peek()) >= '0') && (c <= '9')) {
				value = value * 10 + (c - '0');
				getChar();
			}
			value *= multi;
			return NUM;
		case '+':
		case '*':
		case '/':
		case '%':
			return c;
		default:
			return ERR;
	}
}
